<?php

namespace App\Http\Controllers;

use GeTui;
use Jlylb\GeTui\Messages\NotificationMessage;
use Jlylb\GeTui\Messages\TransmissionMessage;
use Illuminate\Http\Request;
use App\Models\AppNotice;
/**
 * 测试控制器
 *
 * @author litc
 */
class TestController  extends Controller {

    public function notice() {
        $tmpl = GeTui::template();
        $notice = new NotificationMessage($tmpl);
        $msg = [
            'title'=>'测试php通知',
            'content'=>'测试php通知内容',
            'payload'=>'123456789'
        ];
        $notice
            ->title($msg['title'])
            ->text($msg['content'])
            ->transmissionType(2)
            ->transmissionContent($msg)
            ->isRing()
            ->isVibrate();
        return GeTui::pushToApp($notice);
    }
    public function transmission() {
        $tmpl = GeTui::template();
        $notice = new TransmissionMessage($tmpl);
        $msg = [
            'title'=>'测试php通知',
            'content'=>'测试php通知内容',
            'payload'=>'123456789'
        ];
        $notice
            ->transmissionType(2)
            ->transmissionContent($msg);
        return GeTui::pushToApp($notice);
    }
    
    //注册设备
    public function registerApp(Request $request) {
        $data = $request->input();
        $appId = array_get($data, 'appid', null);
        $clientId = array_get($data, 'clientid', null);
        if(!$appId || !$clientId) {
            return [ 'status'=>1, 'message'=>'ok' ];
        }
        $info = AppNotice::where('appid',$appId)->where('clientid',$clientId)->get();
        if($info->isEmpty()){
            $data['update_at'] = date('Y-m-d H:i:s');
            AppNotice::create($data);
        }
        return [ 'status'=>1, 'message'=>'ok' ];
    }

    //测试方法
    public function testAction(Request $request) {
       return ['aa', 'bb', '11111'];
    }
}
